package com.xhb.campusservices.common.lang;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {

    private int code;  //200是正常，非200表示异常
    private String msg;
    private Object data;
    private String token;

    public static Result succ(Object data){
        return succ(ResultCode.SUCCESS,"操作成功",data);
    }
    public static Result succ(Object data,String token){
        return succ(ResultCode.SUCCESS,"操作成功",data,token);
    }

    public static Result succ(int code,String msg,Object data,String token){
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        r.setToken(token);
        return r;
    }

    public static Result succ(int code,String msg,Object data){
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static Result fail(String msg){
        return fail(ResultCode.FAIL,msg,null);
    }

    public static Result fail(String msg,Object data){
        return fail(ResultCode.FAIL,msg,data);
    }

    public static Result fail(int code,String msg){
        return fail(code,msg,null);
    }

    public static Result fail(int code,String msg,Object data){
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
}
